package com.chujian.gateway.client;

import com.chujian.client.gateway.AuthClient;
import com.chujian.framework.auth.Accessor;
import com.chujian.framework.constant.ThreadConst;
import com.chujian.framework.core.tsdata.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * Client持有
 */
@Slf4j
@Component
public class FeignClientHolder {

    @Autowired
    @Lazy
    private AuthClient authClient;

    @Async(ThreadConst.CORE_EXECUTOR)
    public Future<Result<Accessor>> verifyToken(String uri, String token) {
//        log.info("异步校验token, uri:{}", uri);
        Result<Accessor> accessor = authClient.verifyToken(uri, token);
        return new AsyncResult<>(accessor);
    }

}
